package m.jclecai.com.fragment.klpk.pager;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;

import m.jclecai.com.R;
import m.jclecai.com.bean.klpk.bean.PokerBean;
import m.jclecai.com.view.klpk.PagerRecyclerAdapter;
import m.jclecai.com.view.klpk.Poker;

/**
 * Created by andy on 2017/6/7.
 */

public class OptionalFragment extends BasePagerFragment {


    @Override
    public void setIndex(int index) {
        super.setIndex(index);
        //这里需要根据不同的索引，实现不同的业务逻辑，因为其玩法发生了变化，主要玩法有：任选1，任选2，任选3....
        clear();
        //我们要在这个方法做的第一个事情，就是根据不同的index，我们来设置基础的奖金；来实现奖金表；
        switch (index) {
            case 5:
                //任选一
                setItemAward(5);
                break;
            case 6:
                //任选二
                break;
            case 7:
                //任选三
                break;
            case 8:
                //然选四
                break;
            case 9:
                //任选五
                break;
            case 10:
                //任选六
                break;
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //这里我我们将请求网络获取遗漏，让其显示在界面上面；
/*        HttpManager.getAsyn(Constant_Url.KLPK_MISSING_DATA, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(String response) {
                //这里的话， 我们是需要访问网络，请求获取得到遗漏的；
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    JSONObject jsonOm=jsonObject.getJSONObject("omission");
                    String m0 = jsonOm.getString("m0");
                    //这里的话，m0封装了所有遗漏；
                    String[] missData = m0.split(",");
                    setMissingData(missData);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });*/
    }

    @Override
    protected ArrayList<ArrayList<PokerBean>> initData() {

        setIndex(5);
        ///让下面的不显示；
        mLlSelected.setVisibility(View.INVISIBLE);

        //同样这里我们要实现的就是初始化数据；
        ArrayList<ArrayList<PokerBean>> mListData = new ArrayList<>();
        //这里将13个对子进行一个初始化；
        for (int i = 1; i < 14; i++) {
            ArrayList<PokerBean> pokerBeanList = new ArrayList<>();
            pokerBeanList.add(new PokerBean(PokerBean.Category.box, i));

            mListData.add(pokerBeanList);
        }
        return mListData;
    }

    @Override
    public PagerRecyclerAdapter getMyAdapter() {
        return new MyAdapter(null);
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(getActivity(), 4) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
    }


    public class MyAdapter extends PagerRecyclerAdapter {

        public MyAdapter(ArrayList<ArrayList<PokerBean>> listData) {
            super(listData);
        }

        @Override
        protected int getPokerCategory() {
            return Poker.TYPE_OPTIONAL;
        }

        @Override
        public int getItemLayout() {
            return R.layout.item_poke_pair;
        }
    }
}
